<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const getSubStr = (str)=> {
      let fast = 1
      let low = 0
      let result = ''
      const len = str.length
      while(fast <= len) {
        const temp = str.slice(low, fast)
        const tempLen = temp.length
        console.log(low, fast)
        if( temp.slice(0, tempLen-1).includes(temp[tempLen-1]) ) {
          low++
        }else{
          if(tempLen>result.length) result = temp
          fast++
        }
      }
      return result
    }
    console.log(getSubStr('sdfasdgawed'))
  </script>
</body>
</html>